<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //1.将其他类型转为字符串型
        //方式一：toString() 
        var num1 = 10;
        console.log(num1,typeof num1);
        console.log(num1.toString(),typeof num1.toString());
        //方式二：String()
        console.log(String(num1),typeof String(num1));
        //方式三： +''   ******
        console.log(num1+'',typeof (num1+''));
        var num2 = true;
        console.log(num2+'',typeof (num2+''));
        //2.将其他类型转为数字型
        //方式一：parseInt()  转成整数 ********
        var num3 = '123.5';
        console.log(num3,typeof num3);
        console.log(parseInt(num3),typeof parseInt(num3));
        //字符串型转数字型时，遇到字符停止转换
        var num4 = 'v123acb';//NaN
        console.log(num4,typeof num4);
        console.log(parseInt(num4),typeof parseInt(num4));
        //方式二：parseFlaot() 转成小数
        var num4 = '123.4';
        console.log(parseFloat(num4));
        //方式三：Number() 可以转整数也可以小数
        console.log(Number('123'));
        console.log(Number('123.5'));
        //true转换为1  false转换为0
        console.log(Number(true));
        console.log(Number(false));
        //保留小数点 变量.toFixed(小数位数) 
        //只能由数字型调用，最终的结果是字符串型，按照四舍五入
        var num5 = 123.4567;
        console.log(num5.toFixed(2));
        //3.将其他类型转为布尔型 Boolean()
        //null、undefined、0、''、NaN  ---》false
        console.log(Boolean(null));
        console.log(Boolean(undefined));
        console.log(Boolean(0));
        console.log(Boolean(''));
        console.log(Boolean(NaN));
        console.log(Boolean(-1));
        console.log(Boolean(' '));
    </script>
</body>
</html>